<template>
	<view class="container">
		<view class="page_bd page_bd_spacing">
			<view class="kind-list">
				<view class="kind-list_item" v-for="(item, index) in list" :key="index">
					<view :id="item.id" class="fui-flex kind-list_item-hd"
						:class="{ 'kind-list_item-hd_show': item.open }" @tap="kindToggle">
						<view class="fui-flex_item">{{ item.name }}</view>
					</view>
					<view class="kind-list_item-bd" :class="{ 'kind-list_item-bd_show': item.open }">
						<view class="fui-cells" :class="{ 'fui-cells_show': item.open }">
							<block v-for="(page, index2) in item.pages" :key="index2">
								<navigator :url="page.page" class="fui-cell fui-cell_access">
									<view class="fui-cell_bd">{{ page.name }}</view>
									<view class="fui-cell_ft fui-cell_ft_in-access"></view>
								</navigator>
							</block>
						</view>
					</view>
				</view>
			</view>
		</view>
		<tab-bar :currentindex="currentTabIndex"></tab-bar>
	</view>
</template>

<script>
	const fireui = require('@/components/common/fui-clipboard/fui-clipboard.js');
	import {
		mapActions,
		mapState
	} from 'vuex';
	export default {
		data() {
			return {
				currentTabIndex: 0,
				platform: 'uni-app',
				list: [],
				listOnline: [{
					id: 'basic',
					name: '公共页面',
					open: false,
					pages: [{
							"page": "/public/login/wechatlogin",
							"name": "微信授权登录"
						}, {
							"page": "/public/mobile/mobile",
							"name": "绑定手机号"
						}, {
							"page": "/public/login/login",
							"name": "个人中心"
						}, {
							"page": "/public/forgetPwd/forgetPwd",
							"name": "修改密码"
						}, {
							"page": "/public/login/reg",
							"name": "注册"
						}, {
							"page": "/public/auth/auth",
							"name": "公众号授权登录"
						}, {
							"page": "/public/update/update",
							"name": "app更新"
						},
						{
							"page": "/public/icard/icard",
							"name": "身份证验证"
						}
					]
				}]
			};
		},
		computed: {
			...mapState(['networkConnected', 'isOnline'])
		},
		watch: {
			networkConnected(isConnected) {
				if (isConnected) {
					this.menuHandle();
				}
			},
			isOnline(val) {
				if (val) {
					this.menuHandle();
				}
			}
		},
		onLoad() {
			// #ifdef MP
			this.platform = '小程序';
			// #endif
			this.$eventHub.$on('emit', data => {
				setTimeout(() => {
					this.fui.toast('您选择了：' + data);
				}, 350);
			});

			// #ifdef MP-QQ
			let appbox = qq.createAppBox({
				adUnitId: '5a1174cf3a58b4b47be85b54388c5e56'
			});
			appbox.load().then(() => {
				appbox.show();
			});
			// #endif

			// #ifdef MP-WEIXIN
			let interstitialAd = null;
			if (wx.createInterstitialAd) {
				interstitialAd = wx.createInterstitialAd({
					adUnitId: 'adunit-44bbe9a9087910e3'
				});
				interstitialAd.onLoad(() => {});
				interstitialAd.onError(err => {});
				interstitialAd.onClose(() => {});
			}
			if (interstitialAd) {
				interstitialAd.show().catch(err => {
					console.error(err);
				});
			}
			// #endif

			setTimeout(() => {
				this.menuHandle();
			}, 50);
		},
		methods: {
			...mapActions(['getOnlineStatus']),
			async menuHandle() {
				let list = [...this.listOnline];
				this.list = list;
			},
			kindToggle: function(e) {
				var id = e.currentTarget.id,
					list = this.list;
				for (var i = 0, len = list.length; i < len; ++i) {
					if (list[i].id == id) {
						list[i].open = !list[i].open;
					} else {
						list[i].open = false;
					}
				}
				this.list = list;
			},
			github: function(event) {
				//event 当需要异步请求返回数据再进行复制时，需要传入此参数，或者异步方法转为同步方法（H5端）
				fireui.getClipboardData('https://github.com/dingyong0214/fireui-uniapp', res => {
					// #ifdef H5 || MP-ALIPAY
					if (res) {
						this.fui.toast('链接复制成功');
					} else {
						this.fui.toast('链接复制失败');
					}
					// #endif
				}, event);
			},
			mall: function() {
				if (this.list.length < 8) return;
				uni.navigateTo({
					url: '../../template/mall/mall/mall'
				});
			},
			doc: function() {
				uni.navigateTo({
					url: '../../doc/doc/doc'
				});
			}
		}
	};
</script>

<style>
	.container {
		width: 100%;
		padding-bottom: 30rpx;
	}

	.fui-page-title {
		display: flex;
		align-items: center;
		justify-content: center;
		padding: 70rpx 0 30rpx 0;
	}

	.fui-logo {
		height: 108rpx;
		width: 108rpx;
		border-radius: 50%;
	}

	.fui-title {
		font-size: 64rpx;
		padding-left: 20rpx;
		color: #333;
		position: relative;
	}

	.fui-link {
		color: #5677fc;
	}

	.fui-cell {
		padding: 10px 15px;
		position: relative;
		display: -webkit-box;
		display: -webkit-flex;
		display: flex;
		-webkit-box-align: center;
		-webkit-align-items: center;
		align-items: center;
	}

	.fui-cell:before {
		content: ' ';
		position: absolute;
		top: 0;
		right: 0;
		border-top: 1px solid #eaeef1;
		color: #eaeef1;
		left: 15px;
		-webkit-transform: scaleY(0.5);
		transform: scaleY(0.5);
		-webkit-transform-origin: 0 0;
		transform-origin: 0 0;
	}

	.fui-cell:first-child:before {
		display: none;
	}

	.fui-cell_active {
		background-color: #f7f7f9;
	}

	.fui-cell_bd {
		-webkit-box-flex: 1;
		-webkit-flex: 1;
		flex: 1;
	}

	.fui-cell_ft {
		text-align: right;
		color: #999;
	}

	.fui-cell_access {
		color: inherit;
	}

	.fui-cell_ft_in-access {
		padding-right: 13px;
		position: relative;
	}

	.fui-cell_ft_in-access:after {
		content: ' ';
		height: 11px;
		width: 11px;
		border-width: 2px 2px 0 0;
		border-color: #b2b2b2;
		border-style: solid;
		-webkit-transform: matrix(0.5, 0.5, -0.5, 0.5, 0, 0);
		transform: matrix(0.5, 0.5, -0.5, 0.5, 0, 0);
		position: absolute;
		top: 50%;
		margin-top: -7px;
		right: 2px;
	}

	.fui-form-preview_item {
		overflow: hidden;
	}

	.fui-flex {
		display: -webkit-box;
		display: -webkit-flex;
		display: flex;
	}

	.fui-flex_item {
		-webkit-box-flex: 1;
		-webkit-flex: 1;
		flex: 1;
	}

	.fui-page-desc {
		color: #666;
		font-size: 28rpx;
		text-align: center;
		padding-bottom: 50rpx;
	}

	.fui-flex {
		-webkit-box-align: center;
		-webkit-align-items: center;
		align-items: center;
	}

	.fui-cells {
		margin-top: 0;
		opacity: 0;
		-webkit-transform: translateY(-50%);
		transform: translateY(-50%);
		-webkit-transition: 0.3s;
		transition: 0.3s;
	}

	.fui-cells:before,
	.fui-cells:after {
		display: none;
	}

	.fui-cells_show {
		opacity: 1;
		-webkit-transform: translateY(0);
		transform: translateY(0);
	}

	.fui-cell:before {
		right: 15px;
	}

	.kind-list_item {
		margin: 10px 0;
		background-color: #fff;
		border-radius: 2px;
		overflow: hidden;
	}

	.kind-list_item:first-child {
		margin-top: 0;
	}

	.kind-list_img {
		width: 30px;
		height: 30px;
	}

	.fui-img-1,
	.fui-img-2,
	.fui-img-8 {
		width: 32px !important;
		height: 32px !important;
	}

	.fui-img-7 {
		width: 28px !important;
		height: 28px !important;
	}

	.kind-list_item-hd {
		padding: 20px;
		-webkit-transition: opacity 0.3s;
		transition: opacity 0.3s;
	}

	.kind-list_item-hd_show {
		opacity: 0.4;
	}

	.kind-list_item-bd {
		height: 0;
		overflow: hidden;
	}

	.kind-list_item-bd_show {
		height: auto;
	}

	.fui-badge {
		position: absolute;
		width: 80rpx;
		height: 30rpx;
		border-radius: 30rpx 30rpx 30rpx 0;
		color: #fff;
		background: #eb0909;
		font-size: 25rpx;
		font-weight: 400;
		display: flex;
		align-items: center;
		justify-content: center;
		transform: scale(0.8) translateX(100%);
		transform-origin: center center;
		top: -8rpx;
		right: 0;
	}
	.kind-list{
		padding-bottom: 50px;
	}
</style>
